/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
    el: "#main",
    data: {
        listArry: [],
        id: "",
        businessNo: "",
        stateValue: "",
        appliName: "",
        nowPage:1,
        rowNum:10,
        allPages:0,
        pagination: [],
        applyCondition:'',//申请条件
        organCode:'',//机构代码
        jsonStr:'',//json串
        tipMsg: '', // 弹出框提示信息
        jumpPage:'',
        friendprovince: {},
        user_info: {},
        dispute_recourse: "",
        dispute_stats: "",
        selectedVal: '',
        listLength:'',
        sysList: [],  // 系统名称列表
        sysCode:'',  
        equipmentId:'',//设备ID
        exceptionId:'',//异常ID
        phoneNumber:'',//用户手机号
        branchCode:'',
        branchList:[],
        systemNo:'',// 系统名称
    },
    created: function() {
        this.sysname();
        this.branchname();
        // this.queryUser();
        this.backPage();
        // this.modinit();

    },
    methods: {
        // 获取系统名称的value值
        sysValue(e){
            // this.sysCode = e.target.value
            console.log(e);
            this.sysList.forEach((item,index) => {
                if(item.systemName == e) {
                    this.sysCode = item.systemNo
                }
            })
            console.log(this.sysCode);
        },
        // 系统名称列表初始接口
        sysname() {
            axios({
				method: 'post',
				url: App.envUrl.backtrackUrl + 'quality/querySysMaintain',
                // url: 'http://192.168.1.81:8080/slxt-web/quality/querySysMaintain',  // 文华本地
                data: {}
			})
			.then((data) => {
                this.sysList = data.data.data
                console.log(this.sysList)
			})
			.catch((err) => {});
        },
        // 获取机构名称的value值
        organValue(e){
            console.log(e);
            this.branchList.forEach((item,index) => {
                if(item.branchName == e) {
                    this.organCode = item.branchId
                }
            })
        },
        // 机构名称列表初始接口
        branchname() {
            axios({
				method: 'post',
				url: App.envUrl.backtrackUrl + 'branch/queryBranch1',
                data: {}
			})
			.then((data) => {
                this.branchList = data.data.data
                console.log(this.branchList);
			})
			.catch((err) => {});
        },
         //分页
         selectPage(page){
            this.nowPage = page;
            this.queryUser();
        },
        //跳转
        skipPage() {
        	this.nowPage = parseInt(document.getElementById('page-num').value);
        	document.getElementById('page-num').value = '';
            this.queryUser();
        },
        //返回时的显示页
        backPage() {
            this.nowPage = sessionStorage.getItem("page") || 1;
            this.queryUser();
        },
        offsetPage(offset){
            this.nowPage = parseInt(this.nowPage) + parseInt(offset);
            this.queryUser();
        },
        queryUser(pages) {
            const _this = this;
            if (pages) {
                _this.nowPage = pages
            }
            /*if(!_this.appliName && !_this.businessNo && !_this.organCode && !_this.jsonStr) {
                _this.tipMsg = '查询条件不能为空'
                $('#my-alert1').modal({
                    relatedTarget: this,
                });
                return false
            }*/
			_this.listArry = []
            let obj = {
                appliName: _this.appliName,
                businessNo: _this.businessNo, //业务识别号（保单号）
                nowPage:this.nowPage,
                rowNum:this.rowNum,
                organCode:this.organCode,
                projson:this.jsonStr,
                dataState: $('#dataState').val(),
                isPC: $('#isPC').val(),
                equipmentId:this.equipmentId,//设备ID
                exceptionId:this.exceptionId,//异常ID
                phoneNumber:this.phoneNumber,//用户手机号
                sysCode:this.sysCode,//系统名称
            };
            console.log(obj);
            axios({
                    method: "post",
                    // url: "http://localhost:9000/slxt-web/collect/queryDataList",
                    url: App.envUrl.backtrackUrl+"collect/queryDataList",
                    data: obj,
                })
                .then((data) => {
                    console.log("查询",data);
                    var list = data.data.pageCount.datas;
                    // this.nowPage = data.data.pageCount
                        this.allPages = data.data.pageCount.allPages;
                        this.pagination = getPagination(this.nowPage,this.allPages);
                        this.listLength = data.data.pageCou.nowPage;
            if(list.length > 0){nt.allCount;
                        list.forEach((element) => {
                            element.stateValue = "";
                            element.archiveflag = "";  // 归档状态
                            element.datastate = "";    // 录制状态
                            if (element.auditState == 0) {
                                element.stateValue = "未审核";
                            } else if (element.auditState == 1) {
                                element.stateValue = "通过";
                            } else if (element.auditState == 2) {
                                element.stateValue = "拒绝";
                            } else if (element.auditState == 3) {
                                element.stateValue = "审核中";
                            }
                            // 归档状态
                            if(element.archiveFlag == 1) {
                                element.archiveflag = '已归档'
                            }else if(element.archiveFlag == 0) {
                                element.archiveflag = '未归档'
                            }
                            // 录制状态
                            if(element.dataState == 1) {
                                element.datastate = '开始录制'
                            }else if(element.dataState == 2) {
                                element.datastate = '离开录制'
                            }else if(element.dataState == 3) {
                                element.datastate = '完成录制'
                            }

                        });
                        _this.listArry = list;
                    }else if(list.length == 0) {
                        _this.tipMsg = '抱歉，未查询到符合条件的数据！'
                        $('#my-alert1').modal({
                            relatedTarget: _this,
                        });
                    }
                })
                .catch((err) => {});
        },
        resetBtn() {
            const _this = this;
            _this.businessNo = "";
            _this.appliName = "";
            this.jsonStr = '';
            this.organCode = '';
            _this.listArry = [];
            this.nowPage = 1;
            // $('#dataState').val('3');
            // $('#isPC').val('');
            this.branchCode = '',
            this.equipmentId = '',
            this.phoneNumber = '',
            this.exceptionId = '',
            this.sysCode = '',
            this.queryUser();
        },
        // 编辑
        checkdis(row) {
            $('#my-alert2').modal({
                relatedTarget: this,
            });
            this.id = row.id;
            this.businessNo = row.businessNo;
            this.user_info = row;
            this.selectedVal =row.friend_status
            this.dispute_recourse = row.dispute_recourse;
            $("#dispute_start").val(row.dispute_start);
            $("#dispute_end").val(row.dispute_end);
            $("#dispute_stats").find("option:selected").val(row.friend_status);
            $("#dispute_stats").find("option[value='"+ row.friend_status +"']").prop('selected', true);
            $("#dispute_stats").trigger('changed.selected.amui');
        },
        checkModio(item) {
            sessionStorage.setItem("page", this.nowPage);
        	if(item.pluginName == 'timecat'){
        		window.location.href = "newReplay.html?id=" + item.id + "&businessNo=" + (item.businessNo || '') + "&pluginName=" + (item.pluginName || '') + "&pluginVersion=" + (item.pluginVersion || '');
        	}else{
				window.location.href = "newReplay_new.html?id=" + item.id + "&businessNo=" + (item.businessNo || '') + "&pluginName=" + (item.pluginName || '') + "&pluginVersion=" + (item.pluginVersion || '');
			}
        },
        applyModio(id) {
            $('#my-alert').modal({
                relatedTarget: this,
            });
            this.id = id;
        },
        confirmBtn(){
            // console.log(id)
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"approval/updateApplyInfo",
                data: {collectId: this.id,reqDetail: this.applyCondition,appType:'0'},
                // 申请调阅信息接口
            }).then((data) => {
                console.log(data,'申请条件反参');
                window.location.href = "nrrback.html";
            }).catch((err) => {})
        },
        //业务信息按钮
        businessMsg(id,businessNo){
            sessionStorage.setItem("page", this.nowPage);
            window.location.href = "newReplayDetail.html?id=" + id + "&businessNo=" + (businessNo || '');
        },
        //修改进入初始化
        modinit: function() {
            const _this = this;
            let obj = {
                appliName: _this.appliName,
                businessNo: _this.businessNo, //业务识别号（保单号）
            };
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"collect/queryDataList",
                data: obj,
            })
                 .then((data) => {
                    _this.user_info = data.data.pageCount.datas[0];
                    _this.selectedVal = _this.user_info.friend_status
                    _this.dispute_recourse = _this.user_info.dispute_recourse;
                    $("#dispute_start").val(_this.user_info.dispute_start);
                    $("#dispute_end").val(_this.user_info.dispute_end);
                    // _this.stats = _this.user_info.friend_status
                    // $("#dispute_stats").find("option:selected").val(_this.user_info.friend_status)
                    // $("#dispute_stats").find("option:selected").val(1);

                    // $("#dispute_stats").find("option[value='1']").attr("selected", 'selected');
                    // console.log($("#dispute_stats"))
                    // console.log($("#dispute_stats").find("option:selected"))
                    // console.log($("#dispute_stats").find("option:selected").val(1))
                    // $("#dispute_stats").attr("value", '1');
                })

                .catch((err) => {});
        },
        //新增方法
        submit: function() {
            const _this = this;
            let obj1 = {
                dispute_recourse: _this.dispute_recourse, //纠纷原因
                dispute_start: $("#dispute_start").val(), //纠纷开始时间
                dispute_end: $("#dispute_end").val(), //纠纷结束时间
                friend_status: $("#dispute_stats").find("option:selected").val(),//纠纷状态
                id: _this.id,
                businessNo: _this.businessNo, //业务识别号（保单号）
            };
            console.log(obj1);
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"collect/updateCollect",
                data: obj1,
            })
                .then((data) => {
                    console.log(data);
                    // window.location.href =
                    //     "index1.html"
                    window.location.href = "nrrback.html";
                })
                .catch((err) => {});
        },
        friend_return: function() {
            // window.location.href = App.getBaseUrl() + "sys/task/friendcheck.html";
            window.location.href = "nrrback.html";
        },
    },
});

function rowNumChange(value) {
    vm.queryData.rowNum = value;
    vm.queryData.nowPage = 1;
    vm.queryUser();
}
